// ? Element 常用表单校验规则

/**
 *  @rule 手机号
 */
export function checkPhoneNumber(rule: any, value: any, callback: any) {
  const regexp = /^(((13[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(17[3-8]{1})|(18[0-9]{1})|(19[0-9]{1})|(14[5-7]{1}))+\d{8})$/;
  if (value === "") callback("请输入手机号码");
  if (!regexp.test(value)) {
    callback(new Error("请输入正确的手机号码"));
  } else {
    return callback();
  }
}
type Rule = { [x: string]: RegExp };
export const Validate: Rule = {
  perms: /^[A-Z][a-z0-9]{0,10}(:[A-Z][a-z0-9]{0,10})*$/,
  name: /^[A-Z][a-z0-9]{0,19}$/,
  route_path: /^(\/[A-Za-z][A-Za-z0-9_]{0,10})+$/,
  https: /(^https:\/\/([a-z][a-z0-9]{1,10}\.){2}[a-z][a-z0-9]{1,10}(:[0-9]{2,5})*)|(^$)/
};

export function CheckAll(valid: RegExp, errStr: string) {
  return (rule: any, value: any, callback: any) => {
    if (!valid.test(value)) {
      callback(new Error(errStr));
    } else {
      return callback();
    }
  };
}
